import ISEMPTY from "lodash/isEmpty"
import VALUES from "lodash/values"

const newLine = '\r\n';
// const appendLine = (content, row, { separator, quoted }) => {
//     // const line = row.map(data => {
//     //     if (!quoted) return data;
//     //     // quote data
//     //     data = typeof data === 'string' ? data.replace(/"/g, '"') : data;
//     //     return `"${data}"`;
//     // });
//     // content.push(line.join(separator));
//     content.push("//****************************** Messages and signals Database ******************************//");
// };


const defaults = {
    separator: ',',
    quoted: false
};

const header = (content) =>{
    content.push("//****************************** Messages and signals Database ******************************//");
    content.push("")
}

const messagesNumber = (content,num) =>{
    content.push("[NUMBER_OF_MESSAGES] "+num)
    content.push("")
}

const messageInfo = (content,message,{ separator, quoted }) => {
    content.push("[START_MSG] "+ message.info.join(separator))
    content.push("[MSG_ID] "+ message.id.join(separator))
    if(!ISEMPTY(message.singles)){
        message.singles.forEach(single => {
            if(!ISEMPTY(single.info)){
                content.push("[START_SIGNALS] "+single.info.join(separator))
            }
            if(!ISEMPTY(single.desc)){
                single.desc.forEach(desc=>{
                    content.push("[VALUE_DESCRIPTION] "+ VALUES(desc).join(separator))
                })
            }
        });
    }
    content.push("[END_MSG]")
}
export default function mdf(options) {
    options = Object.assign({}, defaults, options);
    const content = [];
    let message ={
        info:[1,2,3,4,5],
        id:[1,2,3,4,5,6,7],
        singles:[
            {
                info:[2,3,4,5,6],
                desc:[{
                    value:2,
                    desc:'jdjd'
                },
                {
                    value:2,
                    desc:'jdjd'
                }]
            },
            {
                info:[2,3,4,5,6],
                desc:[{
                    value:2,
                    desc:'jjjjjjj'
                }]
            }
        ]
    }
    let messages = [message,message,message,message]
    if(!ISEMPTY(messages)){
        header(content)
        messagesNumber(content,messages.length)
        messages.forEach(message => {
            messageInfo(content,message,options)
            content.push("")
        });
    }
 

    // if (columns) {
    //     columnOrder = columns.map(v => {
    //         if (typeof v === 'string') return v;
    //         if (!noHeader) {
    //             column.push(typeof v.title !== 'undefined' ? v.title : v.key);
    //         }
    //         return v.key;
    //     });
    //     if (column.length > 0) appendLine(content, column, options);
    // } else {
    //     columnOrder = [];
    //     datas.forEach(v => {
    //         if (!Array.isArray(v)) {
    //             columnOrder = columnOrder.concat(Object.keys(v));
    //         }
    //     });
    //     if (columnOrder.length > 0) {
    //         columnOrder = columnOrder.filter((value, index, self) => self.indexOf(value) === index);
    //         if (!noHeader) appendLine(content, columnOrder, options);
    //     }
    // }

    // if (Array.isArray(datas)) {
    //     datas.forEach(row => {
    //         if (!Array.isArray(row)) {
    //             row = columnOrder.map(k => (typeof row[k] !== 'undefined' ? row[k] : ''));
    //         }
    //         appendLine(content, row, options);
    //     });
    // }
    return content.join(newLine);
}
